#!/bin/env python

class FunctionCall:
    def __init__(self, function, args):
        self.function = function
        self.args = args

    def call(self): return self.function(*self.args)

class Context:
    def __init__(self):
        self.literals = {
            ':': lambda args: Set(args),
            '*': lambda args: Repeat(args[0], args[1:]),
            '<': lambda args: 1,
            'import': lambda args: 2,
            '&': lambda args: 3
        }
        def getRef(name): return self.objects[str(name)]
        def setRef(name, value): self.objects[str(name)] = value.value()
        self.objects = {'get': getRef, 'set': setRef}

    def get(self, items):
        name = str(items[0])
        args = items[1:]
        try:
            #self.objects.get(name, self.literals.get(name, self.literals[':']))
            if name in self.literals: return self.literals[name](args)
            else                    : return FunctionCall(self.objects[name], args)
        except KeyError: return self.literals[':'](items)


class Set():
    def __init__(self, items): self.items = items
